

              <?php $cur_total_price = 0;
                    $curnum = 0;
                foreach ($bills as $question_item): 
                  $cur_total_price = $cur_total_price + $question_item['total_price'];
                  $curnum = $curnum+1;
                endforeach
              ?>
            <h1>
              订购列表 <small>每分钟刷新一次
              <a href="<?php echo site_url('admin/history?store_id=' . $store_id . '&fromdate=' . $fromdate . '&todate=' . $todate . '&max=' . $max . '&page=' . $page);?>">----->简要列表</a>
              <a href="<?php echo site_url('admin/historydetail?store_id=' . $store_id . '&fromdate=' . $fromdate . '&todate=' . $todate . '&max=' . $max . '&page=' . $page);?>">----->详细列表</a>
            </h1>
          </div>

          <form action=<?php echo site_url('admin/history') ;?> class="form-inline" method="get">
            <div class="form-group">
              <div class="input-group">
                <div class="input-group-addon">店铺名称</div>
                <select style = "width:100%" class="form-control" name="store_id">
                  <option value="-1">所有店铺</option>
                  <?php foreach ($stores as $item): ?>
                    <?php 
                      if ($store_id==$item['store_id']) 
                        echo '<option value="' . $item['store_id'] . '" selected>' . $item['store_name'] . '</option>';
                      else echo '<option value="' . $item['store_id'] . '">' . $item['store_name'] . '</option>';
                    ?>
                  <?php endforeach ?>
                </select>
              </div>
            </div>
            <!--店铺选择下拉框-->
            <div class="form-group">
              <div class="input-group">
                <div class="input-group-addon">开始日期</div>
                <input type="text" class="form-control" name="fromdate" value = "<?php echo $fromdate;?>">
              </div>
            </div>
            <!--开始日期-->
            <div class="form-group">
              <div class="input-group">
                <div class="input-group-addon">结束日期</div>
                <input type="text" class="form-control" name="todate" value = "<?php echo $todate;?>">
              </div>
            </div>
            <!--结束日期-->
            <div class="form-group">
              <div class="input-group">
                <div class="input-group-addon">每页数目</div>
                <input type="text" class="form-control" name="max" value = "<?php echo $max;?>">
              </div>
            </div>
            <!--每页数目-->
            <div class="form-group">
              <div class="input-group">
                <div class="input-group-addon">当前页码</div>
                <input type="text" class="form-control" name="page" value = "<?php echo $page;?>">
              </div>
            </div>
            <!--页码-->

            <button style = "float:right" type="submit" class="btn btn-danger">立即搜索</button>
        </br>
        </br>
        </br>
        </br>

          <div class="input-group">
            <div class="input-group-addon">总的交易额</div>
            <input type="text" class="form-control" name="" value = "<?php echo sprintf("%.2f",$totalprice);?>元" readonly>
          </div>

          <div class="input-group">
            <div class="input-group-addon">总的平均价</div>
            <input type="text" class="form-control" name="" value = "<?php 
                                                                        if ($totallist==0)
                                                                          echo 0;
                                                                        else echo sprintf("%.2f",$totalprice/$totallist);?>元" readonly>
          </div>

          <div class="input-group">
            <div class="input-group-addon">总的订单数</div>
            <input type="text" class="form-control" name="" value = "<?php echo $totallist;?>" readonly>
          </div>

          <div class="input-group">
            <div class="input-group-addon">此页订单额</div>
            <input type="text" class="form-control" name="" value = "<?php echo sprintf("%.2f",$cur_total_price);?>元" readonly>
          </div>

          <div class="input-group">
            <div class="input-group-addon">此页平均价</div>
            <input type="text" class="form-control" name="" value = "<?php 
                                                                        if ($curnum==0)
                                                                          echo 0;
                                                                        else echo sprintf("%.2f",$cur_total_price/$curnum);?>元" readonly>
          </div>

          <div class="input-group">
            <div class="input-group-addon">此页订单数</div>
            <input type="text" class="form-control" name="" value = "<?php echo $curnum;?>" readonly>
          </div>
          </form>

    <!--else $data['curnum'] = $totallist-($data['maxpage']-1)*$max;-->

          
          <!-- Default panel contents -->



              <ul class="pagination" style="float:right">
                <?php 
                  $previous = $page - 1;
                  $next = $page + 1;
                  $url = 'admin/history?store_id=' . $store_id . '&fromdate=' . $fromdate . '&todate=' . $todate . '&max=' . $max . '&page=';

                  if ($previous > 0)
                  {
                    echo '<li><a href="'. site_url($url . $previous) .'">上一页</a></li>';
                  }
                  else
                  {
                    echo '<li><a>上一页</a></li>';
                  }

                  for ($i = 1; $i <= $maxpage; $i++)
                  {
                    if ($i == $page)
                    {
                      echo '<li class="active"><a href="'. site_url($url . $i) .'">' . $i . '</a></li>';
                    }
                    else
                    {
                      if ($i > 0 and $i <= $maxpage)
                      {
                        echo '<li><a href="'. site_url($url . $i) .'">' . $i . '</a></li>';
                      }
                    }
                  }

                  if ($next <= $maxpage)
                  {
                    echo '<li><a href="'. site_url($url . $next) .'">下一页</a></li>';
                  }
                  else
                  {
                    echo '<li><a>下一页</a></li>';
                  }
                ?>
              </ul>
            </br>
            </br>
            </br>
          <div class="panel panel-default">
          <div class="panel-heading">历史记录</div>
          <!-- Table -->
          <table class="table table-striped table-condensed">
            <thead>
              <tr>
                <th>ID</th>
                <th>时间</th>
                <th>店铺</td>
                <th>名称</th>
                <th>电话</th>
                <th>地址</th>
                <th>备注</th>
                <th>打印</th>
                <th>总价</th>
              </tr>
            </thead>
            <tbody>
              <?php foreach ($bills as $question_item): ?>
              <?php $detail = json_decode($question_item['bill_json'], true); ?>
                <tr>
                  <td><?php echo $question_item['bill_id'] ;?></td>
                  <td><?php echo date('Y-m-d H:i:s', $question_item['time']) ;?></td>
                  <td><?php echo $detail['store_name'];?></td>
                  <td><?php echo $question_item['name'] ;?></td>
                  <td><?php echo $question_item['phone'] ;?></td>
                  <td><?php echo $question_item['address'] ;?></td>
                  <?php $note = $question_item['note'];
                        $data_attr = "data-original-title='" . $note . "'";
                  ?>
                  <td>
                    <?php if ($note != ""){ ?>
                      <a  href="#" data-toggle="tooltip" title="" <?php echo $data_attr ;?> >备注</a>
                    <?php }?>
                  </td>
                  <th><?php
                    if ($question_item['print_state'] == "1")
                    {
                      echo "已打印";
                    } 
                    else
                    {
                      echo "未打印";
                    }                    ?></th>
                  <!-- <td><?php echo $question_item['bill_json'] ;?></td> -->
                  <td>
                    <?php echo $detail['total_price'] ;?>
                    <?php if ($showdetail == true){ ?>
                      <table class="table table-bordered">
                        <tbody>
                          <?php foreach ($detail['list'] as $item): ?>
                          <tr>
                            <td><?php echo $item['item_name'] ;?></td>
                            <td><?php echo $item['item_account'] ;?></td>
                            <td><?php echo $item['item_price'] ;?></td>
                          </tr>
                          <?php endforeach ?>
                          
                        </tbody>
                      </table>
                    <?php } ?>
                  </td>
                </tr>
              <?php endforeach ?>

            </tbody>
          </table>    


              <ul class="pagination" style="float:right">
                <?php 
                  $previous = $page - 1;
                  $next = $page + 1;
                  $url = 'admin/history?store_id=' . $store_id . '&fromdate=' . $fromdate . '&todate=' . $todate . '&max=' . $max . '&page=';

                  if ($previous > 0)
                  {
                    echo '<li><a href="'. site_url($url . $previous) .'">上一页</a></li>';
                  }
                  else
                  {
                    echo '<li><a>上一页</a></li>';
                  }

                  for ($i = 1; $i <= $maxpage; $i++)
                  {
                    if ($i == $page)
                    {
                      echo '<li class="active"><a href="'. site_url($url . $i) .'">' . $i . '</a></li>';
                    }
                    else
                    {
                      if ($i > 0 and $i <= $maxpage)
                      {
                        echo '<li><a href="'. site_url($url . $i) .'">' . $i . '</a></li>';
                      }
                    }
                  }

                  if ($next <= $maxpage)
                  {
                    echo '<li><a href="'. site_url($url . $next) .'">下一页</a></li>';
                  }
                  else
                  {
                    echo '<li><a>下一页</a></li>';
                  }
                ?>
              </ul>
          <script>
            $(document).ready(function(){
              $("a").tooltip();
            });
          </script>

        </div>
